package com.atguigu.wordcount.partition;

import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Partitioner;

/**
 * @ClassName PhonePartition
 * @DeScription PhonePartition
 * @Author 剧情再美终是戏
 * @Date 2019/11/19 17:53
 * @Version 1.0
 **/
public class PhonePartition extends Partitioner<Text, NullWritable> {

    public int getPartition(Text key, NullWritable value, int numPartitions) {
        String sub = key.toString().substring(0, 3);
        int partidionIndex = numPartitions - 1;
        if (sub.equals("136")) {
            partidionIndex = numPartitions - 2;
        } else if (sub.equals("137")) {
            partidionIndex = numPartitions - 3;
        } else if (sub.equals("138")) {
            partidionIndex = numPartitions - 4;
        } else if (sub.equals("139")) {
            partidionIndex = numPartitions - 5;
        }
        return partidionIndex;
    }
}
